<?php

/*---------------------------------------
Digital University, v1.0.0
Group Project: G

Design by Toby Tomlinson
Written by Lewis Theobald
----------------------------------------*/

# Force UTF-8
header("Content-Type:text/html; charset=UTF-8");

# Start session handler
session_start();

# Error controls
error_reporting (E_ALL);

# Define constants
define('OI', 1);
define('ROOT_PATH', dirname( __FILE__ ) ."/");
define('SOURCE_PATH', dirname( __FILE__ ) ."/sources/");

# Load configuration
include_once(SOURCE_PATH.'Config.php');
define('PREFIX', $config['prefix']);

# Load our CMS class
include_once(SOURCE_PATH."class/DigitalUniversity.php");

# Initialise the class
$digitalUniversity = new DigitalUniversity($config);
$digitalUniversity->initialise();

# Page switch
if(empty($digitalUniversity->input['page'])) {
	$digitalUniversity->input['page'] = 'home';
}
if(empty($digitalUniversity->user)) {
	$digitalUniversity->input['page'] = 'login';
}

# Get className
$className = ucfirst($digitalUniversity->input['page']);

# Page handler class
include_once(SOURCE_PATH."class/modules/{$className}.php");
ob_start();
	$pageHandler = new $className($digitalUniversity);
	$pageHandler->outputPage();
	$pageContents = ob_get_contents();
ob_end_clean();
unset($pageHandler);

# Header
echo $digitalUniversity->outputDesign('pageHeader');

# Page contents
echo $pageContents;

# Footer
echo $digitalUniversity->outputDesign('pageFooter');

# Close connection
$digitalUniversity->db->closeConnect();

?>